package org.game.db.vo;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.collections4.MapUtils;
import org.bean.ActivityEntryInfo;
import org.bean.ActivityInfo;
import org.constant.smallkey.ActivitySmallKey;

import com.google.common.collect.Maps;

/**
 * @author : DengYing
 * @CreateDate : 2018年3月12日 上午11:19:48
 * @Description ：服务器活动代理
 */
public class ServerActivityProxy implements BaseActivity {
	private ActivityInfo activityInfo;
	

	public ServerActivityProxy(ActivityInfo activityInfo) {
		super();
		this.activityInfo = activityInfo;
	}

	@Override
	public int getActivityId() {
		return activityInfo.getId();
	}

	@Override
	public Map getExtend() {
		return new HashMap<>();
	}

	public Map<Integer, Map<Integer, Integer>> getEntry(int pid) {
		Map<Integer, Map<Integer, Integer>> entryMap =  Maps.newHashMap();
		Map<Integer, ActivityEntryInfo> entrys = activityInfo.getEntrys();
		for (Entry<Integer, ActivityEntryInfo> e : entrys.entrySet()) {
			// 扩展信息
			Map extend = e.getValue().getExtend();
			
			Map<Integer, Integer> statuMaps = (Map<Integer, Integer>) extend.computeIfAbsent(ActivitySmallKey.SUBMIT_LOG, k -> Maps.newHashMap());
			int progress = MapUtils.getIntValue(extend, ActivitySmallKey.PROGRESS);
			int status = MapUtils.getIntValue(extend, ActivitySmallKey.STATUS);
			
			Map<Integer, Integer> map = entryMap.computeIfAbsent(e.getKey(), k -> Maps.newHashMap());
			map.put(ActivitySmallKey.PROGRESS, MapUtils.getIntValue(extend, ActivitySmallKey.PROGRESS));
			map.put(ActivitySmallKey.STATUS, MapUtils.getIntValue(statuMaps, pid, status));
		}
		return entryMap;
	}
	
	public ActivityEntryInfo getActivityEntryInfo(int entryId){
		return activityInfo.getEntrys().get(entryId);
	}
}
